package com.vf.admin.client.service.impl;

import com.vf.admin.client.dao.VipPackageDao;
import com.vf.admin.client.service.VipPackageService;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.VipPackage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@Service
public class VipPackageServiceImpl implements VipPackageService {

    @Autowired
    private VipPackageDao vipPackageDao;

    @Override
    public List<VipPackage> page(Map<String, Object> paraMap, SplitPageBean splitPage) {
        return vipPackageDao.page(paraMap, splitPage);
    }

    @Override
    public void saveOrUpdate(VipPackage params) {
        vipPackageDao.saveOrUpdate(params);
    }

    @Override
    public List<VipPackage> list() {
        List<VipPackage> list = vipPackageDao.list();
        for(VipPackage b : list) {
            b.setPriceDay(b.getPrice().divide(new BigDecimal(b.getNum().toString()).multiply(new BigDecimal("31")), 2, BigDecimal.ROUND_HALF_UP).toPlainString());
            b.setIosPriceDay(b.getIosPrice().divide(new BigDecimal(b.getNum().toString()).multiply(new BigDecimal("31")), 2, BigDecimal.ROUND_HALF_UP).toPlainString());
        }
        return list;
    }

    @Override
    public VipPackage info(Integer id) {
        return vipPackageDao.get(id, VipPackage.class);
    }

    @Override
    public void del(Integer id) {
        String sql = "delete from vip_package where id = " + id;
        vipPackageDao.del(sql, null);
    }
}
